Tangible Software Solutions

C++ to Python Converter Help


Contents

  1. Folder Conversion
  2. File & Snippet Conversion
  3. Command Line Conversion
  4. Header File Options
  5. System Headers
  6. Library Free Function Replacements
  7. Conversion Message Options
  8. Custom String Replacements
  9. Diagnostic Options
  10. File Encoding Options
  11. Additions & Omissions
  12. Miscellaneous Options
  13. Copy Constructors and Copy Assignment


Folder Conversion

The Folder Converter tab allows you to convert all C++ code within a folder. Once the files are converted, you can then view C++ to Python Converter comments, compare converted code files to original code files, and view the converted code folder.

The Conversion History listview displays previously converted sources and allows you to view remaining C++ to Python Converter comments and view the converted code folder.


File & Snippet Conversion

The File & Snippet Converter tab allows you to convert C++ code snippets or files. From the left side textbox, you can type or paste code snippets, insert files, or view C++ to Python Converter sample snippets. Once a file or snippet is converted, you can select and copy the results, save the results to a file, or search the results.


Header File Options


System Headers


Command Line Conversion

C++ to Python Converter can be launched from the command line with two or three parameters. If you specify folders, the first parameter is the folder containing the source files that you wish to convert, and the second parameter is the folder that the converted Python files will be written to. If you specify files, the first parameter is the source code file that you wish to convert, and the second parameter is the name of the converted Python file. If a third parameter is supplied, then it is interpreted as the location of a conversion options file to import before the conversion starts. A conversion options file has the extension '.opt' and is produced by exporting existing options to an xml file from the converter.

e.g. (folder conversion),
"C++ to Python Converter" "C:\C++ Source Files" "C:\Python Converted Files"

e.g. (file conversion),
"C++ to Python Converter" "C:\C++ Source Files\testfile.cpp" "C:\Python Converted Files\testfile.py"

e.g. (folder conversion with a conversion options file specified),
"C++ to Python Converter" "C:\C++ Source Files" "C:\Python Converted Files" "C:\Options\C++ to Python Converter.opt"

Once the command line conversion is complete, C++ to Python Converter will shut down.

Note that C++ to Python Converter must be in double quotes since the executable name contains spaces.


Library Free Function Replacements

C++ to Python Converter is primarily a syntax converter, ignoring most calls to C/C++ library 'free' functions (library functions which don't belong to a class or struct). However, you can specify your own custom replacements for these free function calls. These replacements will occur at the end of the conversion process. You specify the new method name, the expected number of arguments, and whether to transform the function call to an instance method call (using one of the arguments as the instance variable), or a static method call (where you specify a class name in addition to the new method name). You can also specify conversion to an instance or static property.


Conversion Message Options

On this options dialog, you can customize the comment prefixes that the converter uses for messages and also toggle the messages that C++ to Python Converter displays on or off.

You can easily set all or none to display via the 'Select All' and 'Select None' buttons.


Custom String Replacements

C++ to Python Converter allows you to specify your own custom replacements in the converted Python code. This can be useful for cases where you wish to specify a replacement for a C++ library data type that isn't handle by C++ to Python Converter.

For each replacement string you can specify the regex option, when to perform the replacement (pre or post conversion), whether or not to match case, whether to match whole words only, and whether comments or string literals should be modified. The whole words and string literals options do not apply if the regex option is selected.

To span mulitple lines, either paste directly into the 'Find' and 'Replacement' textboxes, or use the escaped characters: \r\n\t.

The "Active" checkbox can be unchecked if you wish to temporarily bypass the replacement.

Replacements are made in the order that they appear on the options dialog. For example, the second replacement is made to each line of code after the first replacement has already been made. To change the order of replacements, use the 'Up' and 'Down' buttons.

For an example of the regex option, you could do a custom replacement of "Foo(x)" with "Bar(x)", where "x" is any argument, by specifying the "Find" field as "Foo(([\sa-zA-Z_$]*))" and the "Replace" field as "Bar$1". Note that there are differences in various regex engines - the regex engine used by the converter is .NET System.Text.RegularExpressions.Regex.


Diagnostic Options

These options are intended to provide information to Tangible Software Solutions if a conversion is taking longer than expected. 'Record processing by file' instructs the converter to make a record of the files processed and the time taken for each process. 'Record the last 100 lines of code parsed before cancelling conversion' instructs the converter to make a record of the most recent lines parsed before you cancelled the conversion.


File Encoding Options

The converter detects input file encoding from the byte order mark (BOM), but if the BOM is missing the converter assumes by default that the file encoding is UTF-8. You can use this option to specify a different default encoding to use in the absence of a BOM. Output is written in the same encoding as the encoding detected for the original file, or your default encoding option if the original coding was not detected via the BOM. For UTF-8, you can choose whether or not to include the BOM for the output - this is normally used in Windows environments.


Additions & Omissions


Miscellaneous Options


Copy Constructors and Copy Assignment

In C++, object variable assignment without using pointers does not perform reference assignment as in Python. Instead these assignments perform a bitwise copy by default or performs the action specified in a copy constructor or assignment operator overload specified in the C++ source code. When C++ to Python Converter determines that an assignment is likely a copy assignment or a call to a copy constructor, it converts them to the Python equivalent and adds a warning to the converted code.

e.g., the following C++ code:
Foo g;
Foo f = g; //uses the copy constructor of type 'Foo'
f = g; //uses the assignment operator overload of type 'Foo'

converts to the Python equivalent:
g = Foo()
f = Foo(g)
f.copy_from(g)

The original copy constructor is converted directly to a Python constructor, and the original assignment operator overload is converted to a 'copy_from' method (since overloading the assignment operator is not possible in Python). C++ compilers automatically generate both the copy constructor and the assignment operator overload if one isn't specified in the C++ source code, but C++ to Python Converter will only convert existing copy constructors and assignment operator overloads and will not create default methods. You may need to code the copy constructor and/or the 'copy_from' method if the original C++ source code relied on the default methods created by the C++ compiler.


Copyright © Tangible Software Solutions, Inc.